﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace BadHabit.Factory.Views {
    /// <summary>
    /// Interaction logic for EditFixedCosts.xaml
    /// </summary>
    public partial class EditFixedCosts : BadHabit.WPFTools.ShapedWindow {


        private string ProposalUId { get; set; }

        public EditFixedCosts(string proposalUId) {
            InitializeComponent();
            ProposalUId = proposalUId;
        }


        public EditFixedCosts() {
            InitializeComponent();
        }

        protected override void OnClosed(EventArgs e) {
            base.OnClosed(e);
            if (Client.FactoryMainWindow != null)
                Client.FactoryMainWindow.IsPopUpOpened = false;
        }

        private void window_Loaded(object sender, RoutedEventArgs e) {
            Client.FactoryMainWindow.IsPopUpOpened = true;
        }


        private void Undo_Executed(object sender, ExecutedRoutedEventArgs e) {
            Data.ProjectDataSet dsProject = DataContext as Data.ProjectDataSet;
            if (dsProject != null)
                dsProject.ProposalFixedCostItem.RejectChanges();
            Close();
        }

        private void Save_Executed(object sender, ExecutedRoutedEventArgs e) {
            Close();
        }

        private void fixedCostsDataGrid_InitializingNewItem(object sender, Microsoft.Windows.Controls.InitializingNewItemEventArgs e) {
            Data.ProjectDataSet.ProposalFixedCostItemRow costRow = Helper.GetRowFromRowView<Data.ProjectDataSet.ProposalFixedCostItemRow>(e.NewItem);

            costRow.Payable = true;
            costRow.FixedPriceItemUId = Guid.NewGuid().ToString().ToLower();
            costRow.ProposalUId = ProposalUId;
            costRow.ItemValue = 0;

        }


    }
}
